package com.pzhyd.sc.util;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
*
* 字符过滤
* @author Gao shiwei
* @version V2012.0.1
* @
*/
public class EnCodeFilter implements Filter {

	private String charset;

	public void destroy() {

	}

	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		/* 设置request的字符编码 */
		req.setCharacterEncoding(charset);
		res.setCharacterEncoding("utf-8");
		/**//* 将request和response传回去,具体为什么请参考jsp基础 */
		chain.doFilter(req, res);
	}

	public void init(FilterConfig config) throws ServletException {
		/**//* 获取xml文件中初始化参数charset对应web.xml文件中的<param-name>charset</param-name>将值传给属性charset */
		charset = config.getInitParameter("charset");
	}

}
